package com.red.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.red.entity.Account;
import com.red.entity.Emp;
import com.red.result.Result;
import com.red.service.EmpService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/emp")
public class EmpController {
    @Autowired
    private EmpService empService;

    @ApiOperation("根据条件查询员工")
    @ApiImplicitParam(name = "anumber",value = "账号")
    @GetMapping("/select")
    public Result findAll(String anumber){
        return new Result(
                empService.list(
                        new QueryWrapper<Emp>()
                                .like(anumber!=null,"anumber",anumber)
                )
        );
    }

    @ApiOperation("添加员工")
    @PostMapping("/save")
    public Result save(Emp emp){
        return new Result(empService.save(emp));
    }

    @ApiOperation("修改员工")
    @PutMapping("/update")
    public Result update(Emp emp){
        return new Result(empService.updateById(emp));
    }

    @ApiOperation("删除员工")
    @DeleteMapping("/delete")
    public Result delete(Integer id){
        return  new Result(empService.removeById(id));
    }
}
